#include "server/rpc.h"

namespace fast_rpc
{
RPCServer& RPCServer::Create(const std::string& name)
{
    static RPCServer server(name);
    return server;
}

Ret RPCServer::Init(const Config& config)
{
    std::string fifo_reader = "";
    GetValueOfKey(config, "fifo_reader", fifo_reader);
    m_reader = std::make_unique<FIFO<Requst, FIFO_ROLE_CREATOR>>(fifo_reader);

    Ret ret = m_reader->Init(config);
    if (ret != Ret::RPC_SUCCESS) {
        return ret;
    }

    std::string fifo_writer = "";
    GetValueOfKey(config, "fifo_writer", fifo_writer);
    m_writer = std::make_unique<FIFO<Response, FIFO_ROLE_CREATOR>>(fifo_writer);
    ret = m_writer->Init(config);
    if (ret != Ret::RPC_SUCCESS) {
        return ret;
    }
    return Ret::RPC_SUCCESS;
}

Ret RPCServer::Start(bool& flag)
{
    while (flag) {
        Requst requst;
        m_reader->Pop(requst);
        
    }
    return Ret::RPC_SUCCESS;
}

Ret RPCServer::Destroy()
{
    return Ret::RPC_SUCCESS;
}

}